package com.cskaoyan.controller;

import com.cskaoyan.bean.Comment;
import com.cskaoyan.bean.comment.CommentListVO;
import com.cskaoyan.bean.comment.OrderReplyBO;
import com.cskaoyan.bean.goods.CommentListBO;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.service.CommentService;
import com.cskaoyan.until.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 商品评论相关模块
 */
@Controller
@RequestMapping("admin")
public class CommentController {

    @Autowired
    CommentService commentService;

    /**
     * 获取评论列表
     */
    @RequestMapping("comment/list")
    @ResponseBody
    public Result getCommentList(BaseParam baseParam, CommentListBO commentListBO) {
        CommentListVO commentListVO = commentService.queryComments(baseParam, commentListBO);

        return Result.ok(commentListVO);
    }

    /**删除评论
     * @param comment 评论信息
     * @return
     */
    @RequestMapping("comment/delete")
    @ResponseBody
    public Result deleteComment(@RequestBody Comment comment) {

        commentService.deleteComment(comment);

        return Result.ok();
    }

    /**
     * 回复评论
     * @param orderReplyBO
     * @return
     */
    @PostMapping("order/reply")
    @ResponseBody
    public Result reply(@RequestBody OrderReplyBO orderReplyBO) {

        Integer affectedRows = commentService.replyComment(orderReplyBO);

        if (affectedRows == 0) {
            Result error = Result.error(622,"订单商品已回复！");
            return error;
        }

        return Result.ok();
    }
}
